<!DOCTYPE html>
<html>
 <head>
  <meta charset="UTF-8" />
  <link rel="stylesheet" type="text/css" media="screen" href="../../global/css/bootstrap.min.css" />
  <link rel="stylesheet" type="text/css" media="screen" href="../../global/layui/css/layui.css" />
  
 </head>
 <body>
  <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
   <form class="form-horizontal" onsubmit="return false" id="form" enctype="multipart/form-data">
    <fieldset>
     <input type="hidden" id="contextId" name="id" />
     <div class="form-group">
      <label class="col-md-2 control-label">名称</label>
      <div class="col-md-10">
       <input class="form-control" placeholder="名称" type="text" name="title" id="title" data-bv-notempty="true" data-bv-notempty-message="用户名 不能为空" />
      </div>
     </div>
      <div class="form-group">
                         <label class="col-md-2 control-label">图片:</label>
                         <div class="col-md-10">
                         <img id="icon" />
                         <input type="file" name="icon" id="icon" />
                         </div>
                         </div>
     <div class="form-group" >
                <label class="col-md-2 control-label">内容</label>
                <!-- 加载编辑器的容器 -->
                <div class="col-md-10">
                    <textarea id="content" name="content" ></textarea>
                </div>
      </div>
     <div class="form-group">
      <label class="col-md-2 control-label">标识</label>
      <div class="col-md-10" style="width: 120px">
       <select class="form-control input-sm" name="flag" id="flag">
       <option value="0">首页头条</option>
       <option value="1" selected="selected">附近公告</option>
       </select>
      </div>
     </div>
     <div class="form-actions">
      <div class="row" align="center">
       <div class="col-md-12">
        <button class="btn btn-primary" onclick="location.href='headList.html'">返回</button>
        <button class="btn btn-primary" type="submit" onclick="add()"> <i class="fa fa-save"></i> 保存 </button>
       </div>
      </div>
     </div>
     
    </fieldset>
   </form>
  </div>
  <script type="text/javascript" src="../../global/js/libs/jquery-2.1.1.min.js"></script>
  <script type="text/javascript" src="../../global/js/jq.js"></script>
  <script type="text/javascript" src="../../global/js/plugin/bootstrapvalidator/bootstrapValidator.min.js"></script>
  <script type="text/javascript" src="../../global/js/common.js"></script>
  <script type="text/javascript" src="../../global/js/my/roles/role.js"></script>
  <script type="text/javascript" src="../../global/layui/layui.js"></script>

<script type="text/javascript" src="../../global/js/libs/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript" src="../../global/js/ajaxfileupload.js"></script>
<script type="text/javascript" src="../../global/js/my/ztree-menu.js"></script>
  <script type="text/javascript">
    //富文本编辑


</script>
  <script type="text/javascript">
  var layedit;
	var index
  layui.use(['layer', 'layedit'], function () {
      var layer = layui.layer;
      layedit = layui.layedit;
      layedit.set({
          uploadImage: {
              url: '../../clyjHeadlines/uploadFile' ,//接口url
              type: 'post' //默认post
          }
      });
  	index = layedit.build('content'); //建立编辑器
  });
      layui.use(['layer', 'laydate'], function () {
          var layer = layui.layer;
          var laydate = layui.laydate;
          laydate.render({
              elem: '#birthday'
          });
      }); 

      $('#form').bootstrapValidator();
       function add() {
           // 表单验证
           var bootstrapValidator = $("#form").data('bootstrapValidator');
           var ids = bootstrapValidator.validate();
           if (!bootstrapValidator.isValid()) {
               return;
           }
           layedit.sync(index);
           var formdata = $("#form").serializeObject(  );
              $("form").ajaxSubmit({
               type: 'post',
               url: '/clyjHeadlines/saveHead',
               traditional: true,
               contentType: "application/json; charsset=utf-8",
               data: JSON.stringify(formdata),
               success: function (data) {
                   layer.msg("添加成功", {shift: -1, time: 1000}, function () {
                       location.href = "headList.html";
                   });
               }
           }); 
       }
</script>
 </body>
</html>